package com.YKFuse.util;

import java.lang.reflect.Field;

/**
 * @author yuank
 * @version 1.0.0
 * @date 2025/2/13 13:48:04
 */
public class BeanUtil {
    public static void copyBeanProperties(Object source, Object target) {
        try {
            // 获取源对象的所有字段,包括非 public 字段
            Field[] fields = source.getClass().getDeclaredFields();
            for (Field field : fields) {
                // 设置可访问性,以便我们可以访问 private 字段
                field.setAccessible(true);
                // 将字段值从源对象复制到目标对象
                field.set(target, field.get(source));
            }
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Failed to copy bean properties", e);
        }
    }
}